package com.wyc.serviceDriverUser.controller;

import com.wyc.internalCommon.request.CarDTO;
import com.wyc.internalCommon.result.ApiResult;
import com.wyc.internalCommon.util.PageUtils;
import com.wyc.serviceDriverUser.dto.Car;
import com.wyc.serviceDriverUser.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CarController {

    @Autowired
    private CarService carService;

    /**
     * 车辆列表
     * @return
     */
    @GetMapping("/car-list")
    public PageUtils list(@RequestParam Map<String,Object> params){
        return carService.queryPage(params);
    }

    /**
     * 插入或修改车辆信息
     * @param car
     * @return
     */
    @PostMapping("/car")
    public ApiResult insertOrUpdateCar(@RequestBody Car car){
        return ApiResult.success(carService.insertOrUpdate(car));
    }

    /**
     * 根据车辆id查询车辆
     * @param carId
     * @return
     */
    @RequestMapping("/car/{carId}")
    public ApiResult<CarDTO> getCarById(@PathVariable("carId") Long carId){
        return ApiResult.success(carService.getById(carId));
    }


}
